﻿package treatBehavior
{
	import flash.geom.Point;
	
	
	public class DivideBehavior implements ITreatBehavior
	{
		                                          //================ Constants ===================

	                                              //================ Constructor =================
		public function DivideBehavior(aVal:Array,dVal:Number,nVal:uint):void
		{	
			arr=aVal;
			d=dVal;
			n=nVal;
			init();
		}
												  //================ Valuables ===================
		private var arr:Array;
		private var d:Number;
		private var n:uint;										  	
	                                              //================ Properties ==================

												  //------------------------------
												  //		abc
												  //------------------------------
	
												  //================ Public Methods ==============
		public function getTreatArr():Array
		{
			var treatRoadArr:Array=new Array();
			var diet:Number=d/n;
			var count:uint=arr.length;
			//分割并添加到_treatRoadArr中
			for(var i=0;i<count-1;i++)
			{
				if(Point.distance(arr[i],arr[i+1])>=diet)
				{
					var m:uint=Point.distance(arr[i],arr[i+1])/diet;
					var dietX:Number=(arr[i+1].x-arr[i].x)/m;
					var dietY:Number=(arr[i+1].y-arr[i].y)/m;
					var p:Point=new Point(arr[i].x,arr[i].y);
					treatRoadArr.push(p);
					for(var k=0;k<m-1;k++)
					{
						var x=arr[i].x+dietX*(k+1);
						var y=arr[i].y+dietY*(k+1);
						var p_2:Point=new Point(x,y);
						treatRoadArr.push(p_2);					
					}
				}
				else{
					treatRoadArr.push(new Point(arr[i].x,arr[i].y));
				}
			}
			treatRoadArr.push(arr[arr.length-1]);
			return treatRoadArr;
		}
												  //================ Private Methods =============
		private function init():void
		{
			
		}
												  //================ Destroy =====================		
	}
}